<?php
require(dirname(__FILE__)."/"."../../inc/common.inc.php");
admin(17);

if($del){
    if (empty($id)){
        refreshto($FROMURL,'删除失败!',2);
    }
    $query = $db->query("DELETE FROM chen_addfrom WHERE id='{$id}'");
    refreshto($FROMURL,'删除成功!',2);

}

if($cancel){
    if (empty($id)){
        refreshto($FROMURL,'取消失败!',2);
    }
    $query = $db->query("update chen_addfrom set is_cancel = 1 WHERE id='{$id}'");

    $info  = $db->get_one( "select * from chen_addfrom where id ='{$id}' " )['activity'];
    # 查询 (补回人数)
    $info_arr = explode(",",$info);
    foreach ($info_arr as $item){
           $db->query( "update chen_activity set people = people - 1 where id = '{$item}' " );
    }

    refreshto($FROMURL,'取消成功!',2);
}
?>

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <script type="text/javascript" src="../js/PIE_IE678.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="../css/H-ui.css"/>
    <link type="text/css" rel="stylesheet" href="../css/H-ui.admin.css"/>
    <link type="text/css" rel="stylesheet" href="../font/font-awesome.min.css"/>
    <!--[if IE 7]>
    <link href="../font/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <title>开奖列表</title>
</head>
<body>
<nav class="Hui-breadcrumb"> <?=get_category(14)?> <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.href='?';" title="刷新" ><i class="icon-refresh"></i></a></nav>
<div class="pd-20">
    <div class="">
        <form class="Huiform" method="get" action="?" >
            <input type="hidden" name="page" value="1">
            <input type="text" placeholder="输入关键词查询" autocomplete="off" value="<?=$keyword?$keyword:''?>" name="keyword"  class="input-text">

            活动：
            <select class="select"  size="1" name="gid">
                <option value="">选择活动</option>
                <?php
                $query = $db->query("select * from {$pre}activity where 1=1 order by id asc");
                while($rs = $db->fetch_array($query)){
                    if ($gid==$rs['id']){
                        $selected1="selected";
                    }else{
                        $selected1='';
                    }
                    echo "<option value=\"".$rs['id']."\" {$selected} {$selected1}>".$rs['activity_route']."</option>";
                }
                ?>
            </select>

            <button type="submit" class="btn btn-success" id="12" name="12" value="12" >
                <i class="icon-search"></i>搜索
            </button>
            <button type="submit" class="btn btn-primary radius" id="12" name="execl" value="execl" ><i class="icon-search"></i> 导出</button>

        </form>
    </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <td >ID</td>
            <td >学校</td>
            <td >姓名</td>
            <td >班级</td>
            <td >性别</td>
            <td >年龄</td>
            <td >身份证号码</td>
            <td >监护人姓名</td>
            <td >监护人身份证号码</td>
            <td >联系电话</td>
            <td >活动</td>
            <td >状态</td>
            <td width="80">操作</td>
        </tr>
        </thead>
        <tbody>
        <?php
        $rows=20;
        if($page<1){
            $page=1;
        }
        $min=($page-1)*$rows;
        if($adminarr['u_gid']==0){
            $isql.="";
        }
        if($keyword!=''  ){
            $isql.=" and ( school like '%{$keyword}%'  or class like '%{$keyword}%' or name like '%{$keyword}%')";
        }
        if($gid != ''){
            $isql .= " and activity in ({$gid}) ";
        }

        if($execl == 'execl') {
            ob_end_clean();
            ob_start();
            ini_set("max_execution_time", "300000");//修改脚本运行时间
            ini_set("max_input_time", "300000");//接收数据所需的最大时间
            ini_set('memory_limit', '9000M');//脚本最大内存限制
            set_time_limit(0);

            header("Content-Type:text/html;charset=utf-8");
            header("Content-type:application/vnd.ms-excel");
            header("Content-Disposition:filename=报名管理.xls");
            header("Content-Description: PHP/INTERBASE Generated Data");
            header("Content-type:application/vnd.ms-excel");

            echo '<meta charset="utf-8">';
            echo "<table border='1'>
                        <tr>
                            <th style='text-align:center;'>序号</th>
                            <th style='text-align:center;'>学校</th>
                            <th style='text-align:center;'>姓名</th>
                            <th style='text-align:center;'>班级</th>
                            <th style='text-align:center;'>性别</th>
                            <th style='text-align:center;'>年龄</th>
                            <th style='text-align:center;'>身份证号码</th>
                            <th style='text-align:center;'>监护人姓名</th>
                            <th style='text-align:center;'>监护人身份证号码</th>
                            <th style='text-align:center;'>联系电话</th>
                            <th style='text-align:center;'>活动</th>
                            <th style='text-align:center;'>状态</th>
                            <th style='text-align:center;'>时间</th>
                        </tr>";
            $ii = 1;
            $sql_select = $db->query("select * from {$pre}addfrom where 1=1 {$isql} order by id desc ");
            while($rs1 = $db->fetch_array($sql_select)) {
                $activity_ssss = $db->array_list("select activity_route from {$pre}activity where 1=1 and id in ({$rs1['activity']})");
                $dddd = $rs['is_cancel'] == 0 ? "正常" : "取消";
                echo '<tr>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $ii . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['school'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['name'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['class'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['sex'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['age'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['idcard'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['j_name'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['j_idcard'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['phone'] . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . implode(",",array_column($activity_ssss,'activity_route')) . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $dddd . '</td>
                            <td style="vnd.ms-excel.numberformat:@;text-align:center;">' . $rs1['add_time'] . '</td>
                        </tr>';
                $ii++;
            }
            echo "</table>";
            exit();
        }


        $rsd=$db->query("select * from {$pre}addfrom where 1=1 {$isql} order by id desc LIMIT $min,$rows");
        while($rs=$db->fetch_array($rsd)){
            $activity_ssss = $db->array_list("select activity_route from {$pre}activity where 1=1 and id in ({$rs['activity']})");
            ?>
        <tr>
            <td><?= $rs['id']?></td>
            <td><?= $rs['school']?></td>
            <td><?= $rs['name']?></td>
            <td><?= $rs['class']?></td>
            <td><?= $rs['sex']?></td>
            <td><?= $rs['age']?></td>
            <td><?= $rs['idcard']?></td>
            <td><?= $rs['j_name']?></td>
            <td><?= $rs['j_idcard']?></td>
            <td><?= $rs['phone']?></td>
            <td>
                <?= $activity_ssss ? implode(",",array_column($activity_ssss,'activity_route')) : "" ?>
            </td>
            <td><?= $rs['is_cancel'] == 0 ?"正常": "取消" ?></td>
            <td>
                <a title="取消" href="?cancel=cancel&id=<?=$rs['id']?>" onClick="if(confirm('是否真的要取消本信息')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-bug"></i></a>
                <a title="删除" href="?del=del&id=<?=$rs['id']?>" onClick="if(confirm('是否真的要删除本信息')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a>
            </td>
            <?php }?>
            <tr class="text-c">
                <td colspan="100"><?=getpage(" {$pre}addfrom  ","where 1=1 ","?keyword=$keyword&gid=$gid",$rows)?></td>
            </tr>
        </tbody>
    </table>

</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript" src="../layer/layer.min.js"></script>
<script type="text/javascript" src="../js/H-ui.js"></script>
<script type="text/javascript" src="../js/H-ui.admin.js"></script>
<script type="text/javascript">
    $(".Huiform").Validform();
    function add(id,w,h,title,url){
        layer_show(w,h,title,url);
    }
</script>
</body>
</html>